package com.koko.controller;

import com.koko.context.BaseContext;
import com.koko.order.dto.OrderGameDTO;
import com.koko.order.dto.PayDTO;
import com.koko.order.entity.Order;
import com.koko.order.vo.OrderVO;
import com.koko.result.Result;
import com.koko.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 下单
     * @param orderGameList
     * @return
     */
    @PostMapping
    public Result<String> addOrder(@RequestBody List<OrderGameDTO> orderGameList) {
        orderService.addOrder(orderGameList);
        return Result.success();
    }

    /**
     * 获取订单信息
     * @return
     */
    @GetMapping
    public Result<OrderVO> getOrder() {
        OrderVO orderVO = orderService.getOrder();
        return Result.success(orderVO);
    }

    /**
     * 查询是否有订单
     * @return
     */
    @GetMapping("/isexist")
    public Result<Long> checkOrderExist() {
        return Result.success(orderService.getOrderId());
    }

    /**
     * 删除订单数据
     * @return
     */
    @DeleteMapping
    public Result<String> deleteOrder() {
        orderService.deleteByUserId(BaseContext.getCurrentId());
        return Result.success();
    }

    /**
     * 支付接口
     * @return
     */
    @PostMapping("/pay")
    public Result<String> payForOrder(@RequestBody PayDTO PayDTO) {
        Result<String> result = orderService.pay(PayDTO);
        return result;
    }
}
